package spms.data.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spms.data.entity.User;
import spms.data.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import spms.data.util.Page;


@RestController
public class UserController {
	private final Logger LOG = LoggerFactory.getLogger(getClass());


	@Autowired //eureka 调用
	//@Reference //dubbo调用
	private UserService userService;

	@RequestMapping(value = "/user/findByUserId",produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Object findByUserId(Integer id){
		LOG.info("开始调用接口/user/findByUserId，参数：{}", id);
		User user = userService.findByUserId(id);
		LOG.info("调用接口/user/findByUserId完成，返回：{}", user);
		return user;
	}

	@RequestMapping(value = "/user/findPage",produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Page<User> findPage(Integer pageNum,Integer pageSize) throws Exception {
		LOG.info("开始调用接口/user/findPage，参数：{},{}", pageNum,pageSize);
		Page<User> page = userService.findPage(pageNum,pageSize,User.class);
		LOG.info("调用接口/user/findPage，返回：{}", page);
		return page;
	}
}
